#include <cstring>
#include "KmyITexture.h"

KmyITexture::KmyITexture(){
    data = NULL;
}

KmyITexture::KmyITexture(int mode, const u8 *data, int w, int h, bool is_buffer)
{
//    this->name = name;
    this->width = w;
    this->height = h;
    this->is_buffer = is_buffer;
    this->is_changed = false;
    this->mode = mode;
    if (!is_buffer){
        switch(mode){
        case TEXTURE_MODE_RGBA8:
            this->data = new u8[w*h*4];
            memcpy(this->data, data, w*h*4);
            break;
        case TEXTURE_MODE_RGBA4:
            this->data = new u8[w*h*2];
            memcpy(this->data, data, w*h*2);
            break;
        case TEXTURE_MODE_RGB565:
            this->data = new u8[w*h*2];
            memcpy(this->data, data, w*h*2);
            break;
        case TEXTURE_MODE_ARGB8:
            this->data = new u8[w*h*4];
            memcpy(this->data, data, w*h*4);
            break;
        case TEXTURE_MODE_RGB8:
            this->data = new u8[w*h*3];
            memcpy(this->data, data, w*h*3);
            break;
        case TEXTURE_MODE_ARGB4:
            this->data = new u8[w*h*2];
            memcpy(this->data, data, w*h*2);
            break;
        }
    }else{
        this->data = (u8*)data;
    }
    gid = -1;
}

void KmyITexture::finalize(){
    if (!is_buffer){
        delete[] data;
    }
}

void KmyITexture::disDraw(){
    is_drawed = false;
}
